package com.quanyue.haircut.shop.mapper;

import com.quanyue.haircut.domain.entity.UserCoupon;
import com.quanyue.haircut.shop.dto.CouponDetail;
import com.vhuomai.mybatis.mapper.auto.AutoMapper;
import com.vhuomai.mybatis.mapper.page.Page;
import com.vhuomai.mybatis.mapper.page.PageRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CouponUserMapper extends AutoMapper <UserCoupon, Integer> {
    @Select("<script>select u.id, u.expire_time, c.coupon_name, c.coupon_type, c.discount, c.least, c.save, s.shop_name "
            + "from qy_user_coupon u "
            + "inner join qy_coupon c on u.coupon_id = c.id and c.del_flag=0 "
            + "inner join qy_shop s on u.shop_id = s.id "
            + "where u.user_id = #{userId} <if test = \"delFlag == 1 || delFlag == 0\"> and u.del_flag = ${delFlag} </if> "
            + "</script>")
    Page <CouponDetail> findByBit(@Param("request") PageRequest request,
                                  @Param("delFlag") Integer bit,
                                  @Param("userId") Integer userId);
}
